﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WpfWordsLearner
{
	public sealed class WordsSplitter : IDisposable
	{
		private string m_content = null;

		public WordsSplitter()
		{
		}

		public WordsSplitter(string data)
		{
			m_content = data;
		}

		public void SetData(string data)
		{
			m_content = data;
		}
		
		public List<string> SplitByWords()
		{
			string[] words = System.Text.RegularExpressions.Regex.Split(m_content, @"\W+", System.Text.RegularExpressions.RegexOptions.Compiled);
			List<string> list = new List<string>();

			var regEx = new System.Text.RegularExpressions.Regex(@"^[0-9]+$", System.Text.RegularExpressions.RegexOptions.Compiled);

			foreach (string word in words)
			{
				if (list.Contains(word) || regEx.IsMatch(word))
					continue;
				list.Add(word);
			}
			return list;
		}

		public void Dispose()
		{
			if (m_content != null)
				m_content = null;
		}
	}
}
